import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

class Mypool
{
    public BlockingQueue<Runnable>runnable=new LinkedBlockingQueue<>();
   public Mypool(int n)
   {
       for(int i=0;i<n;i++)
       {
           Thread t=new Thread(()->
           {
               while(true)
               {
                   try {
                       Runnable b=runnable.take();
                       b.run();
                   } catch (InterruptedException e) {
                       throw new RuntimeException(e);
                   }
               }

           });
           t.start();
       }
   }
    public void put(Runnable task)
    {
        try {
            runnable.put(task);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}

public class Mythread27 {
    public static void main(String[] args) {
        Mypool mypool=new Mypool(10);
        for(int j=0;j<1000;j++)
        {
            int n=j;
            mypool.put(new Runnable() {
                @Override
                public void run() {
                    System.out.println(n);

                }
            });
        }

    }

}
